

Component({
    options: {
        styleIsolation: 'isolated'
    },
    properties: {
        propA: {
            type: String,
            value: 'default value',
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        countdown: ''
    },

    attached() {
        this.showtime()
        var that = this
        setInterval(function () {
            that.showtime()
        }, 1000)
    },
    methods: {
        showtime() {
            var nowtime = new Date();
            var endtime = new Date(this.properties.propA);

            var lefttime = parseInt((endtime.getTime() - nowtime.getTime()) / 1000);
            if (lefttime <= 0) {
                var countdown = "已截止"
                this.setData({
                    countdown: countdown
                })
            } else {
                var d = parseInt(lefttime / (24 * 60 * 60));
                var h = parseInt(lefttime / (60 * 60) % 24);
                var m = parseInt(lefttime / 60 % 60);
                var s = parseInt(lefttime % 60);
                h = this.addZero(h);
                m = this.addZero(m);
                s = this.addZero(s);
                var countdown = "剩余时间：" + d + "天 " + h + "小时 " + m + "分 " + s + "秒 ";
                this.setData({
                    countdown: countdown
                })
            }
        },
        addZero(i) {
            if (i < 10) {
                i = "0" + i;
            } return i;
        }
    },

})